﻿using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using RBS.Core.Extension;
using RBS.DBUtility;
using RBS.Common;
namespace RBS.Core.DAL
{
    //V_Deed
    public partial class V_Deed
    { 
        #region  ExtensionMethod
        /// <summary>
        /// 获得查询分页数据
        /// </summary>
        public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            var strSql = new StringBuilder();
            strSql.Append("select * FROM V_Deed  where ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where 1=1 " + strWhere);
            }
            recordCount = Convert.ToInt32(DbHelperSQL.GetSingle(PagingHelper.CreateCountingSql(strSql.ToString())));
            return DbHelperSQL.Query(PagingHelper.CreatePagingSql(recordCount, pageSize, pageIndex, strSql.ToString(), filedOrder));
        }
        #endregion  ExtensionMethod  
        public Model.V_Deed GetModel(int batchid)
        {
            var strSql = new StringBuilder();
            strSql.Append("select * FROM V_Deed  where  batchid=" + batchid); 
            DataSet ds = DbHelperSQL.Query(strSql.ToString()); 
            if (ds.Tables[0].Rows.Count > 0)
            {
                var model = ds.Tables[0].Rows[0].ConvertToEntity<RBS.Core.Model.V_Deed>();
                return model;
            }
            else
            {
                return null;
            } 
        }

         /// <summary>
         /// 
         /// </summary>
         /// <param name="id"></param>
         /// <param name="status"></param>
         /// <returns></returns>
        public bool UpdateAdvertisBatchState(int id, int status)
        {
            string strSql = "update P_Advertis_Batch set ABStatus=@Status where Id=@Id";
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4),
                    new SqlParameter("@Status", SqlDbType.Int,4)
			};
            parameters[0].Value = id;
            parameters[1].Value = status; 
            return DbHelperSQL.Exists(strSql, parameters);
        }  
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool UpdateAdvertisListState(int id, int status)
        {
            string strSql = "update P_Advertis_List set ALStatus=@Status where Id=@Id";
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4),
                    new SqlParameter("@Status", SqlDbType.Int,4)
			};
            parameters[0].Value = id;
            parameters[1].Value = status;
            return DbHelperSQL.Exists(strSql, parameters);
        }


    }
}

